// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { handle_for_select, handle_select_and_open_in_dir, handle_select_and_open_in_file } from './selection';
import { string_handler } from './string_handlers/string_router';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

	// Use the console to output diagnostic information (console.log) and errors (console.error)
	// This line of code will only be executed once when your extension is activated
	console.log('Congratulations, your extension "cqh-change-string-case" is now active!');

	// The command has been defined in the package.json file
	// Now provide the implementation of the command with registerCommand
	// The commandId parameter must match the command field in package.json
	console.log('Congratulations, your extension "cqh-change-string-case" is now active!');

	// The command has been defined in the package.json file
	// Now provide the implementation of the command with  registerCommand
	// The commandId parameter must match the command field in package.json
	let disposable = vscode.commands.registerTextEditorCommand('cqh-change-string-case.select', (textEditor, edit) => {
		// The code you place here will be executed every time your command is executed
		if (!textEditor.selection.isEmpty) {
			return;
		}
		handle_for_select(textEditor, edit);
		// Display a message box to the user
		// vscode.window.showInformationMessage('Hello World!');
	});

	context.subscriptions.push(disposable);


	let string_handler_disposable = vscode.commands.registerTextEditorCommand('cqh-change-string-case.string-handler', (textEditor, edit) => {
		if (textEditor.selection.isEmpty) {
			handle_for_select(textEditor, edit);
		}
		// string_handler
		string_handler(textEditor, edit);
		// const selection = textEditor.selections[0];
		// // vscode.Position
		// const text = textEditor.document.getText(selection);
		// string_function(textEditor, edit, (p: string) => {
		//     if (/[a-zA-Z]+/.test(p)) {
		//         return p.toUpperCase()
		//     } else {
		//         return p
		//     }
		// })
		// cancel_selection(textEditor, edit);
	})
	context.subscriptions.push(string_handler_disposable);



	let open_disposable = vscode.commands.registerTextEditorCommand("cqh-change-string-case.select_and_open_file", async (textEditor, edit) => {
		await handle_select_and_open_in_file(textEditor, edit);
	})
	context.subscriptions.push(open_disposable)

	let open_dir_disposable = vscode.commands.registerTextEditorCommand("cqh-change-string-case.select_and_open_dir", async (textEditor, edit) => {
		await handle_select_and_open_in_dir(textEditor, edit);
	})

}

// this method is called when your extension is deactivated
export function deactivate() { }
